package com.shuang.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.shuang.mapper.DbGoodsPropertyParamMapper;
import com.shuang.pojo.DbGoodsPropertyParam;
import com.shuang.pojo.DbGoodsPropertyParamExample;
import com.shuang.pojo.DbGoodsPropertyParamExample.Criteria;
import com.shuang.service.DbGoodsPropertyParamService;
@Service("dbGoodsPropertyParamService")
public class DbGoodsPropertyParamServiceImpl implements DbGoodsPropertyParamService {

	@Resource(name="dbGoodsPropertyParamMapper")
	private DbGoodsPropertyParamMapper dbGoodsPropertyParamMapper;
	
	@Override
	public Map<String, Object> getPropertyInfoById(Long gId) {
		DbGoodsPropertyParamExample example = new DbGoodsPropertyParamExample();
		Criteria criteria = example.createCriteria();
		criteria.andGIdEqualTo(gId);
		List<DbGoodsPropertyParam> result = dbGoodsPropertyParamMapper.selectByExampleWithBLOBs(example);
		Map<String, Object> map=new HashMap<String, Object>();
		if(result!=null&&result.size()>0){
			map.put("status", 200);
			map.put("data", result.get(0));
		}else{
			map.put("status", 404);
			map.put("data", "未查询到指定id商品的属性信息");
		}
		
		return map;
	}

	@Override
	public Map<String, Object> updatePropertyParamInfoById(Long gId,
			String property) {
		DbGoodsPropertyParam record = new DbGoodsPropertyParam();
		record.setGppUpdateTime(new Date());
		record.setGppParamData(property);
		DbGoodsPropertyParamExample example = new DbGoodsPropertyParamExample();
		Criteria criteria = example.createCriteria();
		criteria.andGIdEqualTo(gId);
		int result=dbGoodsPropertyParamMapper.updateByExampleSelective(record, example);
		Map<String, Object> map=new HashMap<String, Object>();
		if(result>0){
			map.put("status", 200);
		}else{
			map.put("status", 404);
			map.put("data", "更新失败");
		}
		
		return map;
	}

}
